package com.example.xjtuse_pc.mobilesafe.LostGuid;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import com.example.xjtuse_pc.mobilesafe.R;
import com.example.xjtuse_pc.ui.SettingItemView;

public class Setup2Activity extends BaseSetupAcitivity {
    private SettingItemView siv_bond_sim;
    private TelephonyManager tm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setup2);
        tm= (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        siv_bond_sim= (SettingItemView) findViewById(R.id.siv_bond_sim);
        String s=sp.getString("sim",null);
        siv_bond_sim.setChecked(!TextUtils.isEmpty(s));
        siv_bond_sim.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences.Editor ed=sp.edit();
                if (siv_bond_sim.isChecked()){
                    ed.putString("sim", null);
                    siv_bond_sim.setChecked(false);
                }else{
                    siv_bond_sim.setChecked(true);
                    String sim=tm.getSimSerialNumber();
                    ed.putString("sim", sim);

                }
                ed.commit();

            }
        });
    }

    @Override
    public void showNext() {
        String sim = sp.getString("sim", null);
        if(TextUtils.isEmpty(sim)){
            //没有绑定
            Toast.makeText(this, "sim卡没有绑定", Toast.LENGTH_SHORT).show();
            return ;
        }

        Intent intent = new Intent(Setup2Activity.this, Setup3Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.tran_in,R.anim.tran_out);
    }

    @Override
    public void showPre() {
        Intent intent = new Intent(Setup2Activity.this, Setup1Activity.class);
        startActivity(intent);
        finish();
        overridePendingTransition(R.anim.retran_in,R.anim.retran_out);
    }

}
